﻿using System;
using System.Collections.Generic;
using CommunityServer.WebServices.Blogs;
using System.Xml.Linq;
using System.Xml;
using System.Linq;
using System.IO;

namespace CSImport
{
    class Program
    {
        static XNamespace wp = "http://wordpress.org/export/1.0/";

        static void Main(string[] args)
        {
            //admin user key: a0kkja61

            //printBlogs();
            printXMLBlogs();
            Console.Read();

        }

        public static void printXMLBlogs()
        {

            String xmlFileName = "C:\\Users\\bettsw\\Downloads\\wordpress.2008-07-29.xml";

            //XDocument doc = XDocument.Load(xmlFileName);
            XElement postsFromFile = XElement.Load(xmlFileName);
            //var catagories = postsFromFile.Element("channel").Elements(wp + "category");

            foreach (XElement item in GetCatagories(postsFromFile))
            {
                Console.WriteLine("Catagory nickname:\t" + item.Element(wp + "category_nicename").Value);
                Console.WriteLine("Catagory parent:\t" + item.Element(wp + "category_parent").Value);
                Console.WriteLine("Catagory name:\t" + item.Element(wp + "cat_name").Value);
                Console.WriteLine();
            }
        }

        static IEnumerable<XElement> GetCatagories(XElement rssDoc)
        {
            var items = rssDoc.Element("channel").Elements(wp + "category");
            foreach (var item in items)
                yield return item;
        }

        public static void printBlogs()
        {
            String url = "http://15.5.191.67/cs";
            String userName = "admin";
            String webServiceKey = "a0kkja61";
            BlogsService service = new BlogsService(url, userName, webServiceKey);

            Blog blog = service.GetBlog("sample_weblog");
            List<BlogPost> posts = service.GetBlogPosts(blog.Id);

            if (posts != null)
            {
                Console.Out.WriteLine(posts.Count);
                foreach (BlogPost post in posts)
                {
                    Console.WriteLine(post.Title);
                }
            }
            else
            {
                Console.WriteLine("No Posts found");

            }

            BlogPost newPost = new BlogPost();
            BlogPostSettings settings = new BlogPostSettings();
            //settings.EnableComments
            //settings.
        }
    }
}
